﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class Manager_FeedBackList : System.Web.UI.PageEx
{
    private string strPageCode = "F0000A";
    private string strLoginResult = string.Empty;

    private int iPageCount = 0;
    private int iRecordCount = 0;
    private string strQuery = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!DalEx.DbManagerEx.CheckLoginRight(UserType, UserId, strPageCode, ref strLoginResult))
        {
            FineUI.Alert.Show(strLoginResult, FineUI.MessageBoxIcon.Warning);
            Response.Redirect("Login.aspx");
        }
        if (!Page.IsPostBack)
        {
            DataBinds();
        }
    }
    private void DataBinds()
    {
        DataSet ds = WebBase.Comm.SelectByPage("dbFeedbook", "*", strQuery, "fId", "fId", 0, 1, gridList.PageSize, gridList.PageIndex + 1, out iPageCount, out iRecordCount);
        gridList.RecordCount = iRecordCount;
        gridList.DataSource = ds;
        gridList.DataBind();
    }
    protected void gridDataList_RowDataBound(object sender,EventArgs e)
    {
        
    }    
    protected void gridList_RowCommand(object sender, FineUI.GridCommandEventArgs e)
    {        
        Dictionary<int, Dictionary<int, string>> modifiedDict = gridList.GetModifiedDict();
        int iSelectId = 0;
        string strCommandName = e.CommandName.ToString();
        string strResult = string.Empty;
        if (!string.IsNullOrEmpty(strCommandName))
        {
            int iSelectIndexId = e.RowIndex;
            string strSelectId = gridList.Rows[iSelectIndexId].DataKeys[0].ToString();
            Int32.TryParse(strSelectId, out iSelectId);

            Model.DbFeedbook dbFeedBook = DalEx.DbFeedBackEx.Select(iSelectId);
            if (dbFeedBook != null)
            {
                hfFId.Text = dbFeedBook.FId.ToString();
                txtTitle.Text = dbFeedBook.FTitle;
                winForm.Popup = true;
            }
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        int iSelectId = 0;
        int.TryParse(hfFId.Text, out iSelectId);
        string strContents = HttpUtility.HtmlEncode(heContent.Text);
        Model.DbFeedbook dbFeedBook = DalEx.DbFeedBackEx.Select(iSelectId);
        if (dbFeedBook != null)
        {
            Model.DbReplyBook dbReplyBook = new Model.DbReplyBook();
            dbReplyBook.RMid = UserId;
            dbReplyBook.RUserName = UserName;
            dbReplyBook.RNotes = strContents;
            dbReplyBook.RFeedId = iSelectId;
            dbReplyBook.RDatetime = DateTime.Now;

            if (DalEx.DbReplyBookEx.Insert(dbReplyBook) > 0)
            {
                dbFeedBook.FIsReply = 1;
                DalEx.DbFeedBackEx.Update(dbFeedBook);
                sfObject.GetResetReference();
                FineUI.Alert.Show("已成功回复！","信息提示", FineUI.MessageBoxIcon.Information);
            }
        }
    }
    protected void ttboxKeywords_Trigger1Click(object sender,EventArgs e)
    {
        ddlSearchClass.SelectedIndex = 0;
        ttboxKeywords.Text = string.Empty;
    }
    protected void ttboxKeywords_Trigger2Click(object sender,EventArgs e)
    {
        string strKeywords = ttboxKeywords.Text.Trim();
        int iSelectType = 0;
        int.TryParse(ddlSearchClass.SelectedValue, out iSelectType);
        if (iSelectType >= 0)
        {
            strQuery += " and fIsReply=" + iSelectType;
        }
        if (!string.IsNullOrEmpty(strKeywords))
        {
            strQuery += " and (fUser='" + strKeywords + "' or fTel='" + strKeywords + "' or fNotes like '%" + strKeywords + "%')";
        }
        DataBinds();
    }
    protected void btnSelectDelete_Click(object sender,EventArgs e)
    {
        string strResult = string.Empty;
        List<int> lstSelectRowId = WebBase.Comm.GetGridSeleteRowId(gridList);
        foreach (int iSelectId in lstSelectRowId)
        {
            DalEx.DbFeedBackEx.Delete(" and fId=" + iSelectId, ref strResult);
        }
        FineUI.Alert.Show(strResult, FineUI.MessageBoxIcon.Information);
        DataBinds();
    }
    protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
    {
        int iPageSize = 20;
        int.TryParse(ddlPageSize.SelectedValue, out iPageSize);
        gridList.PageSize = iPageSize;
        DataBinds();
    }
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        DataBinds();
    }
    protected void gridList_PageIndexChange(object sender, FineUI.GridPageEventArgs e)
    {
        gridList.PageIndex = e.NewPageIndex;
        DataBinds();
    }
}
